package ngat.oss;

import ngat.message.OSS.*;
import ngat.util.logging.*;
import ngat.phase2.*; 
import ngat.instrument.*;
import ngat.phase2.nonpersist.*;

import java.util.*;
import java.io.*;

import jyd.dbms.*;
import jyd.storable.*;
import jyd.collection.*;

/**
 * Action: Retreive list of Users belonging to a specified Tag. 
 * @author S.N.Fraser
 * $Id: LIST_USERSImpl.java,v 1.1 2006/11/27 08:45:00 snf Exp $
 */
public class LIST_USERSImpl extends TransactionImpl {

    Path tagPath;

    public LIST_USERSImpl(Path tagPath) {
	super();
	tagPath = tagPath;
    }

    public LIST_USERSImpl(LIST_USERS request) {
	super(request);
	tagPath = request.getTagPath();
    }

    /**
     * Retrieves the List of Users for Tag specified
     * @return list or an OSS_Error.
     */
    public TRANSACTION_DONE exec() { 

	Tag  tag  = null;
	User user = null;
	
	Vector list = new Vector(); // Holds the list of Proposal paths.
	
	Transaction t = null;
	try {
	    t = Transaction.current();
	    
	    tag = OSS_Utilities.fetchTag(tagPath);
	    
	    // Check it exists.
	    if (tag == null) {
		logger.log(1, CLASS, id, "exec", 
			   "Tag: "+tagPath.toString()+" Not in database.");
		return error(TRANSACTION.PATH_RESOLUTION_ERROR, 
				     "Could not find Tag: "+tagPath.toString());
	    }
		
	    // Iterate round the Tag's Users.
	    Iterator it = tag.listAllUsers();
	    
	    while (it.hasNext()) {
		user = (User)it.next();
		list.addElement(user.getDescriptor());
	    }
	    	    
	} finally {
	    t.commit();
	}
		
	LIST_USERS_DONE done  = new LIST_USERS_DONE(id);
	done.setUserList(list);
	done.setSuccessful(true);
	return done;

    }

}

/** $Log: LIST_USERSImpl.java,v $
/** Revision 1.1  2006/11/27 08:45:00  snf
/** Initial revision
/**
/** Revision 1.1  2001/02/23 18:51:14  snf
/** Initial revision
/** */
